﻿@page "/identity/roles"
@attribute [Authorize(IdentityPermissions.Roles.Default)]
@using Volo.Abp.Identity
@using Microsoft.AspNetCore.Authorization
@using Volo.Abp.PermissionManagement.Blazor.Components
@using Volo.Abp.Identity.Localization
@using Volo.Abp.AspNetCore.Components.Web
@using Volo.Abp.AspNetCore.Components.Web.Theming
@using Volo.Abp.BlazoriseUI.Components.ObjectExtending
@using Volo.Abp.AspNetCore.Components.Web.Theming.Layout
@inject AbpBlazorMessageLocalizerHelper<IdentityResource> LH
@using Microsoft.Extensions.Localization
@using Volo.Abp.UI.Navigation.Localization.Resource
@inject IStringLocalizer<AbpUiNavigationResource> LUiNavigation

@inherits AbpCrudPageBase<IIdentityRoleAppService, IdentityRoleDto, Guid, GetIdentityRolesInput, IdentityRoleCreateDto, IdentityRoleUpdateDto>
<Card>
    <CardHeader>
        @* ************************* PAGE HEADER ************************* *@
        <PageHeader Title="@L["Roles"]"
                    BreadcrumbItems="@BreadcrumbItems"
                    Toolbar="@Toolbar">
        </PageHeader>
    </CardHeader>
    <CardBody>
        @* ************************* DATA GRID ************************* *@
        <AbpExtensibleDataGrid TItem="IdentityRoleDto"
                               Data="@Entities"
                               ReadData="@OnDataGridReadAsync"
                               TotalItems="@TotalCount"
                               ShowPager="true"
                               PageSize="@PageSize"
                               CurrentPage="@CurrentPage"
                               Columns="@RoleManagementTableColumns">
        </AbpExtensibleDataGrid>
    </CardBody>
</Card>

@* ************************* CREATE MODAL ************************* *@
@if (HasCreatePermission)
{
    <Modal @ref="CreateModal" Closing="@ClosingCreateModal">
        <ModalContent Centered="true">
            <Form>
                <ModalHeader>
                    <ModalTitle>@L["NewRole"]</ModalTitle>
                    <CloseButton Clicked="CloseCreateModalAsync"/>
                </ModalHeader>
                <ModalBody>
                    <Validations @ref="@CreateValidationsRef" Model="@NewEntity" ValidateOnLoad="false">
                        <Validation MessageLocalizer="@LH.Localize">
                            <Field>
                                <FieldLabel>@L["DisplayName:RoleName"] *</FieldLabel>
                                <TextEdit @bind-Text="@NewEntity.Name" Autofocus="true">
                                    <Feedback>
                                        <ValidationError/>
                                    </Feedback>
                                </TextEdit>
                            </Field>
                            <ExtensionProperties TEntityType="IdentityRoleCreateDto" TResourceType="IdentityResource" Entity="@NewEntity" LH="@LH" ModalType="ExtensionPropertyModalType.CreateModal" />
                        </Validation>
                        <Field>
                            <Check TValue="bool" @bind-Checked="@NewEntity.IsDefault">@L["DisplayName:IsDefault"]</Check>
                            <Check TValue="bool" @bind-Checked="@NewEntity.IsPublic">@L["DisplayName:IsPublic"]</Check>
                        </Field>
                    </Validations>
                </ModalBody>
                <ModalFooter>
                    <Button Color="Color.Primary" Outline Clicked="CloseCreateModalAsync">@L["Cancel"]</Button>
                    <SubmitButton Clicked="@CreateEntityAsync"/>
                </ModalFooter>
            </Form>
        </ModalContent>
    </Modal>
}
@* ************************* EDIT MODAL ************************* *@
@if (HasUpdatePermission)
{
    <Modal @ref="EditModal" Closing="@ClosingEditModal">
        <ModalContent Centered="true">
            <Form>
                <ModalHeader>
                    <ModalTitle>@L["Edit"]</ModalTitle>
                    <CloseButton Clicked="CloseEditModalAsync"/>
                </ModalHeader>
                <ModalBody>
                    <Validations @ref="@EditValidationsRef" Model="@EditingEntity" ValidateOnLoad="false">
                        <input type="hidden" name="ConcurrencyStamp" @bind-value="EditingEntity.ConcurrencyStamp"/>
                        <Validation MessageLocalizer="@LH.Localize">
                            <Field>
                                <FieldLabel>@L["DisplayName:RoleName"] *</FieldLabel>
                                <TextEdit @bind-Text="EditingEntity.Name" Autofocus="true">
                                    <Feedback>
                                        <ValidationError/>
                                    </Feedback>
                                </TextEdit>
                            </Field>
                            <ExtensionProperties TEntityType="IdentityRoleUpdateDto" TResourceType="IdentityResource" Entity="@EditingEntity" LH="@LH"  ModalType="ExtensionPropertyModalType.EditModal" />
                        </Validation>
                        <Field>
                            <Check TValue="bool" @bind-Checked="@EditingEntity.IsDefault">@L["DisplayName:IsDefault"]</Check>
                            <Check TValue="bool" @bind-Checked="@EditingEntity.IsPublic">@L["DisplayName:IsPublic"]</Check>
                        </Field>
                    </Validations>
                </ModalBody>
                <ModalFooter>
                    <Button Color="Color.Primary" Outline Clicked="CloseEditModalAsync">@L["Cancel"]</Button>
                    <SubmitButton Clicked="@UpdateEntityAsync"/>
                </ModalFooter>
            </Form>
        </ModalContent>
    </Modal>
}

@if (HasManagePermissionsPermission)
{
    <PermissionManagementModal @ref="PermissionManagementModal"/>
}
